﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ahi.Config;
using System.Diagnostics;
using System.IO;

namespace Ahi
{
    public partial class LoginForm : DevExpress.XtraEditors.XtraForm
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(AppConfig.Current.KullaniciAdi))
                editKullaniciAdi.Text = AppConfig.Current.KullaniciAdi;
            if (!string.IsNullOrEmpty(AppConfig.Current.VeritabaniSunucusu))
                editVeritabani.Text = AppConfig.Current.VeritabaniSunucusu;
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            Login();
        }

        private void Login()
        {
            if (Program.Login(editKullaniciAdi.Text, editSifre.Text, editVeritabani.Text))
                this.Close();
        }

        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            AppConfig.Current.KullaniciAdi = editKullaniciAdi.Text;
            AppConfig.Current.VeritabaniSunucusu = editVeritabani.Text;
            AppConfig.Current.SaveToXml();
        }

        private void editKullaniciAdi_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                Login();
        }

        private void editSifre_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                Login();
        }

        private void editVeritabani_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                Login();
        }
    }
}